package jfilters.filters;

/*
    Copyright Janne Liljeblad 2008.

    This file is part of JFilters.

    JFilters is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    JFilters is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with JFilters.  If not, see <http://www.gnu.org/licenses/>.
*/

import java.awt.image.*;
import java.awt.*;
import java.awt.geom.*;

public abstract class JFilter implements BufferedImageOp
{
	//--- Channels.
	public static final int RED = 0;
	public static final int GREEN = 1;
	public static final int BLUE = 2;
	public static final int ALPHA = 3;

	//--- For bitwise ops. blue is 0 and does not need to be bit shifted.
	public static final int alpha = 24;
	public static final int red = 16;
	public static final int green = 8;
	public static final int alpha_mask = 0x00ffffff;

	//--- offsets
	protected int offX = 0;
	protected int offY = 0;

	protected Rectangle mask = null;

	//--- BufferedImageOp methods
	public BufferedImage createCompatibleDestImage( BufferedImage src, ColorModel dstCM )
	{
		return new BufferedImage( src.getWidth(), src.getHeight(), BufferedImage.TYPE_4BYTE_ABGR );
	}
	public Rectangle2D getBounds2D( BufferedImage src )
	{
		return new Rectangle( 0, 0, src.getWidth(), src.getHeight() );
	}
	public Point2D getPoint2D( Point2D srcPt, Point2D dstPt )
	{
		if( dstPt == null ) return new Point2D.Double( srcPt.getX() + offX, srcPt.getX() + offY );
		dstPt.setLocation( srcPt.getX() + offX, srcPt.getX() + offY );
		return dstPt;
	}
	public RenderingHints getRenderingHints() 
	{
		return null;
	}

	//--- helper methods.
	public static int[] getBank( BufferedImage img )
	{
		WritableRaster imgRaster = img.getRaster();
		DataBufferInt dbuf = (DataBufferInt) imgRaster.getDataBuffer();
		return dbuf.getData( 0 );
	}

	//--- setters
	public void setMask( Rectangle mask ){ this.mask = mask; }

}//end class